package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 一项积分明细
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_integral_details)
public class IntegralDetailsItemView extends LinearLayout {
    @ViewById
    TextView itemIntegralDetailsFraction, itemIntegralDetailsNameText,
            itemIntegralDetailsDataText, itemIntegralDetailsSymbolText;


    public IntegralDetailsItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public IntegralDetailsItemView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    /**
     * 加载数据
     *
     * @param position
     * @param type     0 积分明细 1:经验明细
     */
    public void loadData(int position, JSONObject itemData, int type) {

        String score = TypeUtils.getJsonString(itemData, (type == 0 ? "score" : "experience"));
        if (score != null && score.indexOf("-") == -1) {

            // <!-- 加分 -->
//			itemIntegralDetailsFraction.setSelected(true);
            itemIntegralDetailsSymbolText.setText("+");
        } else {
            // <!-- 减分 -->
//			itemIntegralDetailsFraction.setSelected(false);
            itemIntegralDetailsSymbolText.setText("-");

        }
        itemIntegralDetailsFraction.setText(score.substring(1, score.length()));
        itemIntegralDetailsNameText.setText(TypeUtils.getJsonString(itemData,
                "reason"));
        itemIntegralDetailsDataText.setText(TypeUtils.getJsonString(itemData,
                "time"));

    }

}
